// 探索发现相关 API

import request from './index';
import type { ApiResponse } from '@/types/api';
import type { ExpertCategory, HealthArticle, TrendingTopic, FeedItem } from '@/types/explore';
import {
  mockGetExpertCategories,
  mockGetCategoryArticles,
  mockGetRecommendedFeed,
  mockGetTrendingTopics,
  mockGetArticleDetail
} from '@/mock/explore';

const USE_MOCK = import.meta.env.VITE_USE_MOCK === 'true';

/**
 * 获取专家领域分类
 */
export const getExpertCategories = async (): Promise<ApiResponse<{ categories: ExpertCategory[] }>> => {
  if (USE_MOCK) {
    return mockGetExpertCategories();
  }
  
  return request.get('/explore/categories');
};

/**
 * 获取分类下的文章
 */
export const getCategoryArticles = async (categoryId: string): Promise<ApiResponse<{ articles: HealthArticle[] }>> => {
  if (USE_MOCK) {
    return mockGetCategoryArticles(categoryId);
  }
  
  return request.get(`/explore/categories/${categoryId}/articles`);
};

/**
 * 获取推荐信息流
 */
export const getRecommendedFeed = async (): Promise<ApiResponse<{ feed: FeedItem[] }>> => {
  if (USE_MOCK) {
    return mockGetRecommendedFeed();
  }
  
  return request.get('/explore/feed');
};

/**
 * 获取热门话题
 */
export const getTrendingTopics = async (): Promise<ApiResponse<{ topics: TrendingTopic[] }>> => {
  if (USE_MOCK) {
    return mockGetTrendingTopics();
  }
  
  return request.get('/explore/trending');
};

/**
 * 获取文章详情
 */
export const getArticleDetail = async (articleId: string): Promise<ApiResponse<HealthArticle>> => {
  if (USE_MOCK) {
    return mockGetArticleDetail(articleId);
  }
  
  return request.get(`/explore/articles/${articleId}`);
};